package com.liyuci.eleon.admin.dept;

import com.liyuci.core.controller.BaseController;
import com.liyuci.core.entity.RestPageResult;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 部门控制器.
 * @author liyuci
 * @date Oct 18, 2017 7:24:37 PM
 */
@Controller
@RequestMapping("/admin/dept")
@Api(tags = {"部门信息"})
public class DeptController extends BaseController<Dept>
{
	@ApiOperation(value = "部门列表")
	@GetMapping("list")
	@ResponseBody
	public RestPageResult list(HttpServletRequest request, ModelMap modelMap)
	{
		//使用jpa提供的分页类
        List<Sort.Order> list = new ArrayList<Sort.Order>();
        Sort.Order order = new Sort.Order(Direction.DESC, "name");
        list.add(order);
        Sort sort = new Sort(list);
        Pageable pageable = new PageRequest(0, 5, sort);
        Page<Dept> pageDept = this.service.list(pageable);
		return RestPageResult.ok(pageDept);
	}
	
	@ApiOperation(value = "新增/编辑部门")
	@GetMapping("addEdit/{id}")
	public String addEdit(@PathVariable("id") String id)
	{
		return addEditPage();
	}
}
